import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';

import { Block } from '../../../components/detail/index';
import Theme from '../../../native-base-theme/variables/commonColor';
import {Loading, BlankBackground, ListFooter } from '../../../components';

const data = [{
  type: 'block',
  showHeader: true,
  title: '资产信息',
  contents: [{
    label: '资产编码',
    key: 'assetCode',
    value: '',
  }, {
    label: '资产描述',
    key: 'description',
    value: '',
  }, {
    label: '管理特性',
    key: 'isSpecialequip',
    value: '',
  }, {
    label: '成本中心名称',
    key: 'costCenterDesc',
    value: '',
  }],
}];

class assetInformation extends Component {
  constructor(props) {
    super(props);
    this.state = {
      isError: false,
    };
  }

  _getPage = () => {
    const list = [];
    let key = 0;
    data.forEach(item => {
      this._deepTraversal(item);
      list.push(<Block data={item} key={key} />);
      key += 1;
    });
    return list;
  }

  _deepTraversal = (obj) => {
    if (!obj) return;
    if (obj.contents && obj.contents.length) {
      obj.contents.map(item => this._deepTraversal(item));
    } else {
      obj.value = this._getValueByFiled(obj.key, obj.type);
    }
  }

  _getValueByFiled = (filed, type) => {
    const value = this.props.data[filed];
    if (value) {
      if (type === 'image') {
        return [value];
      }
      return value;
    }
    if (type === 'image') {
      return [];
    }
    return '';
  }

  render() {
    const { isError } = this.state;
    return (
      // <BlankBackground isError={isError} onRefresh={this._onInitRefresh} />
      <View style={styles.tabContent}>
        {this._getPage()}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  tabContent: {
    backgroundColor: Theme.myPrimary,
    color: '#ffffff',
    width: '100%',
    flex: 1,
  },
});

export default assetInformation;
